package com.link.auth.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;

/**
 * @author huanglongjian
 * @Descpription 获取Bean对象
 */
@Configuration
public class BeanTools implements ApplicationContextAware {
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext context) {
        applicationContext = context;
    }

    @SuppressWarnings({"unchecked", "rawtypes"})
    public static Object getBean(Class className) {
        Object restTemplate = null;
        try {
            /*restTemplate = MultiCorpUtil.getCorpServiceBean(className);//获取租户个性化bean
            if (restTemplate == null) {
                restTemplate = applicationContext.getBean(className);
            }*/
            restTemplate = applicationContext.getBean(className);
            return restTemplate;
        } catch (Exception e) {
            return null;
        }
    }

    public static Object getBean(String beanName) {
        try {
            Object restTemplate = applicationContext.getBean(beanName);
            return restTemplate;
        } catch (Exception e) {
            return null;
        }
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }
}
